#include "myoled.h"

struct display_info disp;

void myoled_show(void *arg)
{
	unsigned char *buffer = (unsigned char *)arg;

	oled_clear(&disp);
	oled_putstrto(&disp, 0, 9 + 1, "-------smart home-------");
	disp.font = font1;

	oled_putstrto(&disp, 0, 27 + 3, buffer);
	disp.font = font2;
	oled_send_buffer(&disp);

	/**	oled_putstrto(disp, 0, 9+1, "Welcome       to");
		disp->font = font1;

		oled_putstrto(disp, 0, 18+2, "----OrangePi----");
		disp->font = font2;

		oled_putstrto(disp, 0, 27+3, "This is 0.96OLED");
		oled_putstrto(disp, 0, 36+4, "");
		oled_putstrto(disp, 0, 45+5, "");
		disp->font = font1;

		oled_putstrto(disp, 0, 54, "*****************");
		oled_send_buffer(disp);
	**/
}

void myoled_show_test()
{
	oled_putstrto(&disp, 0, 9 + 1, "------------------------");
	disp.font = font1;

	oled_putstrto(&disp, 25, 27 + 3, "garbage is");
	oled_putstrto(&disp, 25, 45 + 5, "dry waste");
	disp.font = font1;

	oled_send_buffer(&disp);
}

void show_error(int err, int add)
{
	printf("\nERROR: %i, %i\n\n", err, add);
}

void myoled_clear()
{
	oled_clear(&disp);
}

void myoled_init()
{
	int e;
	memset(&disp, 0, sizeof(disp));
	disp.address = OLED_I2C_ADDR;
	disp.font = font2;

	e = oled_open(&disp, FILENAME);

	if (e < 0)
	{
		show_error(1, e);
	}
	else
	{
		e = oled_init(&disp);
		oled_clear(&disp);
		if (e < 0)
		{
			show_error(2, e);
		}
	}
}